local skel = fk.CreateSkill {
  name = "rmt__tufua",
}

Fk:loadTranslationTable{
  ["rmt__tufua"] = "途缚",
  [":rmt__tufua"] = "当你受到伤害时，你可以改为减1点体力上限；当你造成伤害时，你可以改为回复1点体力或体力上限。",

  ["#rmt__tufua1-invoke"] = "途缚：是否减1点体力上限，防止你受到的 %arg 点伤害？",
  ["#rmt__tufua2-invoke"] = "途缚：是否选择一项，防止你对 %dest 造成的伤害？",
  ["rmt__tufua_maxhp"] = "加1点体力上限",

  ["$rmt__tufua1"] = "国士之礼每深，报德之分未一，善始无终。",
  ["$rmt__tufua2"] = "宿心难负，设使秦运必穷，关西之地，会非吾有。",
}

skel:addAcquireEffect(function (self, player, is_start)
  if player.maxHp > player:getMark(skel.name) then
    player.room:setPlayerMark(player, skel.name, player.maxHp)  --体力上限上限，绷
  end
end)

skel:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_cost  = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name =  skel.name, prompt = "#rmt__tufua1-invoke:::"..data.damage })
  end,
  on_use  = function(self, event, target, player, data)
    player.room:changeMaxHp(player, -1)
    data:preventDamage()
  end,
})

skel:addEffect(fk.DamageCaused, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return player:isWounded() or player.maxHp < player:getMark(skel.name)
    end
  end,
  on_cost  = function(self, event, target, player, data)
    local choices = {"Cancel"}
    if player.maxHp < player:getMark(skel.name) then
      table.insert(choices, 1, "rmt__tufua_maxhp")
    end
    if player:isWounded() then
      table.insert(choices, 1, "recover")
    end
    local choice = player.room:askToChoice(player, {
      choices = choices, skill_name = skel.name, all_choices = {"recover", "rmt__tufua_maxhp", "Cancel"},
      prompt = "#rmt__tufua2-invoke::"..data.to.id,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use  = function(self, event, target, player, data)
    local room = player.room
    if event:getCostData(self).choice == "recover" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = skel.name,
      })
    else
      room:changeMaxHp(player, 1)
    end
    data:preventDamage()
  end,
})

skel:addEffect(fk.MaxHpChanged, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player.maxHp > player:getMark(skel.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, skel.name, player.maxHp)  --体力上限上限，绷
  end,
})

return skel
